package cn.bob.basic.aop;

import cn.bob.basic.anno.Aopanno;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author bob
 * @data 2022/10/13-12:46
 */
@Aspect
@Component
public class LogAop {
    @Pointcut("@annotation(cn.bob.basic.anno.Aopanno)")
    private void pointCut(){}

    @Around("pointCut()")
    private Object around(ProceedingJoinPoint pjp){

        // 获取到所有的方法
        MethodSignature signature = (MethodSignature) pjp.getSignature();
        Method method = signature.getMethod();
        Aopanno annotation = method.getAnnotation(Aopanno.class);
        String method1 = annotation.method();
        String methodDes = annotation.methodDoc();
        System.out.println(method1+"::"+methodDes);
        Object proceed = null;
        try {
            proceed = pjp.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }

        return proceed;
    }
}
